﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

namespace AUV5.Web.Manage
{
    public partial class DictionaryManage : PageBaseBackend
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindKey(); 
            }
        }

        //绑定已存在的键
        private void BindKey()
        {
            ArrayList list = BLL.BaseDataBLL.Instance.GetKeyList();
            ddlKey.Items.Insert(0,new ListItem("-select-","0"));
            for (int i = 0; i < list.Count; i++)
            {
                ddlKey.Items.Add(list[i].ToString());
            }
        }

        //添加
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtKey.Text.Trim() == "")
            {
                lbMessage.Text = "键不能为空！";
                return;
            }
            else if (txtValue.Text.Trim() == "")
            {
                lbMessage.Text = "值不能为空！";
                return;
            }
            else
            {
                Model.BaseData data = new Model.BaseData();
                data.DataKey = txtKey.Text.Trim();
                data.DataValue = txtValue.Text.Trim();
                data.State = (int)Common.Enum.auvState.Enabled;
                data.IsDel = (int)Common.Enum.auvDel.NotDel;
                data.CreateDate = DateTime.Now;
                data.UpdateDate = DateTime.Now;
                data.BeginDate = DateTime.Now;
                data.EndDate = DateTime.Now;

                if (BLL.BaseDataBLL.Instance.GetDetail(txtKey.Text.Trim(),txtValue.Text.Trim())!=null)
                {
                    BLL.BaseDataBLL.Instance.Add(data);
                }
                else
                {
                    lbMessage.Text = "该键值对已存在！";
                }
            }

        }

        //选择已存在的Key
        protected void ddlKey_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlKey.SelectedIndex != 0)
            {
                txtKey.Text = ddlKey.SelectedItem.Text;
            }
        }
    }
}